package com.nuc.wxh.vaccine_appointment.vaccines.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nuc.wxh.vaccine_appointment.vaccines.entity.AdminHospital;
import com.nuc.wxh.vaccine_appointment.vaccines.entity.VaccineAppointment;
import com.nuc.wxh.vaccine_appointment.vaccines.mapper.VaccineAppointmentMapper;
import com.nuc.wxh.vaccine_appointment.vaccines.service.VaccineAppointmentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Arrays;

/**
 * <p>
 * 疫苗预约详细情况 服务实现类
 * </p>
 *
 * @author 王鑫浩
 * @since 2021-03-10
 */
@Service
public class VaccineAppointmentServiceImpl extends ServiceImpl<VaccineAppointmentMapper, VaccineAppointment> implements VaccineAppointmentService {

    @Override
    public Page<VaccineAppointment> selectPage(Page<VaccineAppointment> pageParam, VaccineAppointment vaccineAppointment) {
        //条件构造器
        QueryWrapper<VaccineAppointment> wrapper = new QueryWrapper<>();
        //普通的排序分页查询
        if (vaccineAppointment == null) {
            return baseMapper.selectPage(pageParam, wrapper);
        }
        //获取对象参数
        String vaccineName= vaccineAppointment.getVaccineName();
        Integer isState = vaccineAppointment.getIsState();
        //条件

        if (!StringUtils.isEmpty(vaccineName)) {
            wrapper.like("vaccine_name", vaccineName);
        }
        if (StringUtils.isEmpty(isState)) {
            wrapper.in("is_state", Arrays.asList("4","3"));

        }else if(isState.intValue()==4){
            wrapper.likeRight("is_state", isState);
        }else {
            wrapper.in("is_state", Arrays.asList("4","3"));
        }

        return baseMapper.selectPage(pageParam, wrapper);
    }
}
